package com.yst.feign1.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;

/**
 * 调用feign接口时，统一设置日志trackId
 */
@Slf4j
@Component
public class FeignTrackIdRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        log.info("FeignTrackIdRequestInterceptor");
        String trackId = MDC.get("trackId");
        if (StringUtils.isBlank(trackId)) {
            return;
        }
        requestTemplate.header("trackId", trackId);
    }
}
